package com.eurabia.eggchat.controller.admin;


import com.eurabia.eggchat.VO.ResultVO;
import com.eurabia.eggchat.pojo.SysEggchatRoleUser;
import com.eurabia.eggchat.pojo.SysEggchatUser;
import com.eurabia.eggchat.pojo.form.SysEggchatUserForm;
import com.eurabia.eggchat.pojo.query.SysEggchatUserQuery;
import com.eurabia.eggchat.service.SysEggchatUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;

/**
 * SysEggchatUserController 
 */
@Controller
@RequestMapping("/sysEggchatUser")
public class SysEggchatUserController {
    private static final String LIST_PAGE = "modules/sysEggchatUser/list";
	private static final String SHOW_PAGE = "modules/sysEggchatUser/show";
    private static final String ADD_PAGE = "modules/sysEggchatUser/add";
    private static final String EDIT_PAGE = "modules/sysEggchatUser/edit";
    @Autowired
    private SysEggchatUserService sysEggchatUserService;
	
	/**
     * SysEggchatUser页面
     */
    @RequestMapping(value = "/listPage", method = RequestMethod.GET)
    public final String listPage() {
        return LIST_PAGE;
    }

    /**
     * 查询 SysEggchatUser
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public final ResultVO list(final SysEggchatUserQuery query) {
        return new ResultVO(sysEggchatUserService.findByPage(query));
    }

    /**
     * 查询 SysEggchatUser
     */
    @RequestMapping(value = "/listAll", method = RequestMethod.GET)
    @ResponseBody
    public final ResultVO listAll(final SysEggchatUserQuery query) {
        return new ResultVO(sysEggchatUserService.find(query));
    }

    /**
     * 查看 SysEggchatUser
     */
    @GetMapping(value = "/show_{id}")
    @ResponseBody
    public final ResultVO showOne(@PathVariable("id") final String id) {
        ResultVO resultVO = new ResultVO();
        ArrayList<SysEggchatUser> sysEggchatUsers = new ArrayList<>();
        SysEggchatUser sysEggchatUser = sysEggchatUserService.get(id);
        sysEggchatUsers.add(sysEggchatUser);
        resultVO.setData(sysEggchatUsers);
        return resultVO;
    }

    /**
     * 新增 SysEggchatUser
     */
    @RequestMapping(value = "/add", method = RequestMethod.GET)
    public final String addPage() {
        return ADD_PAGE;
    }

    /**
     * 新增 SysEggchatUser
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ResponseBody
    public final ResultVO add(final SysEggchatUserForm form) {
        sysEggchatUserService.add(form);
        return new ResultVO();
    }

    /**
     * 修改 SysEggchatUser
     */
    @RequestMapping(value = "/edit_{id}", method = RequestMethod.GET)
    public final ModelAndView editPage(@PathVariable("id") final String id) {
        ModelAndView mav = new ModelAndView(EDIT_PAGE);
        mav.addObject("result", sysEggchatUserService.get(id));
        return mav;
    }

    /**
     * 修改 SysEggchatUser
     */
    @RequestMapping(value = "/edit", method = RequestMethod.POST)
    @ResponseBody
    public final ResultVO edit(final SysEggchatUserForm form) {
        sysEggchatUserService.update(form);
        return new ResultVO();
    }

    /**
     * 根据id删除 SysEggchatUser
     */
    @RequestMapping(value = "/delete_{id}", method = RequestMethod.POST)
    @ResponseBody
    public final ResultVO delete(@PathVariable("id") final String id) {
        sysEggchatUserService.delete(id);
        return new ResultVO();
    }

    /**
     * 启用 SysEggchatUser
     */
    @RequestMapping(value = "/enabled_{id}", method = RequestMethod.POST)
    @ResponseBody
    public final ResultVO enabled(@PathVariable("id") final String id) {
        sysEggchatUserService.changeEnabled(id, 1);
        return new ResultVO();
    }

    /**
     * 停用 SysEggchatUser
     */
    @RequestMapping(value = "/disabled_{id}", method = RequestMethod.POST)
    @ResponseBody
    public final ResultVO disabled(@PathVariable("id") final String id) {
        sysEggchatUserService.changeEnabled(id, 2);
        return new ResultVO();
    }
}